//
//  Character.m
//  MagicForce
//
//  Created by QuickSoluion on 8/3/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Character.h"
#import "TauThuy.h"
#import "CotGio.h"
#import "BangHieu.h"
#import "NuocTung.h"
#import "Chay.h"
#import "Bom.h"
#import "ChuGame.h"
#import  "XeKieu.h"
#import  "bb.h"
#import  "bbx.h"
#import  "bbt.h"
@implementation Character



#pragma mark SUPPORT
+(int)getClassIDByClassName: (Class)c
{		
	if(c==[TauThuy class])
	{
		return 1;
		
	}
	else if(c==[CotGio class])
	{
		return 2;
		
	}
	else if(c==[BangHieu class])
	{
		return 3;
		
	}
	else if(c==[NuocTung class])
	{
		return 4;
		
	}
	else if(c==[Chay class])
	{
		return 5;
		
	}
	else if(c==[Bom class])
	{
		return 6;
		
	}
	else if(c==[ChuGame class])
	{
		return 7;
		
	}
	else if(c==[XeKieu class])
	{
		return 8;
		
	}
	else if(c==[bb class])
	{
		return 9;
		
	}
	else if(c==[bbx class])
	{
		return 10;
		
	}
	else if(c==[bbt class])
	{
		return 11;
		
	}
	return 0;		
	
}

#pragma mark PROTOTYPE
-(void)setCharacterAttribute
{
	/// prototype
}
#pragma mark INIT
-(id)initWithParent: (CCLayer*)parentLayer
{
	[self setCharacterAttribute];
	
	//NSLog(@"_textureName =%@",_textureName);
	//NSLog(@"tagFile =%@",tagFile);
	int tagg = [Character getClassIDByClassName:[self class]];
	CCSpriteBatchNode* spriteSheet = (CCSpriteBatchNode*)[parentLayer getChildByTag:tagg];
	if (spriteSheet == nil) {
		[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"%@.plist", _textureName]];
		spriteSheet = [CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@"%@.png", _textureName]];
		[parentLayer addChild:spriteSheet z:1000 tag:tagg];
	}
	if ((self = [super initWithSpriteFrameName:[NSString stringWithFormat:@"%@1.%@",_textureName,tagFile]])) {
		
		[spriteSheet addChild:self];
	}
		
	return self;
}

#pragma mark CREATE_ANIMATION
-(id)createAnimation
{
	
	NSMutableArray *animFramesTurnback = [NSMutableArray array];
	for (int i = 1; i <= nFrame; i++) {
		[animFramesTurnback addObject:
		 [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
		  [NSString stringWithFormat:@"%@%d.%@", _textureName, i,tagFile]]];
	}	
	CCAnimation *animTurnback = [CCAnimation 
								 animationWithFrames:animFramesTurnback delay:fTimer/nFrame];
	
	
	id action = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animTurnback restoreOriginalFrame:NO]] ;
	
	
	return action;	
	
}









-(void)dealloc
{
	[super dealloc];
}
@end
